<!DOCTYPE html>
<html lang="en">
<title>课表更新通知</title> <#import "/layout/layout.html" as body/>
<@body.page>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-lg-10">
		<h2>运营管理</h2>
		<ol class="breadcrumb">
			<li><a href="#">运营管理</a></li>
			<li class="active"><strong>课表更新消息发送记录</strong></li>
		</ol>
	</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox float-e-margins">
				<div class="ibox-title overflow">
					<h5 class="pull-left">课表更新消息发送记录</h5>
					<a href="to_notice_add" class="btn btn-sm btn-primary pull-right">新增消息</a>
				</div>
				<div class="ibox-content">
					<div class="table-responsive">
						<table class="table table-hover table-center dataTables-example">
							<thead>
							<tr>
								<th>序号</th>
								<th>标题</th>
								<th>上课地点</th>
								<th>发送状态</th>
								<th>创建人</th>
								<th>发送时间</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="course_notice_list">
							</tbody>
						</table>
					</div>
				</div>
				<div class="ibox-content overflow">
					<h4 class="pull-left">合计：<span id="total_count">0</span>条发送记录</h4>
					<div id="copot-page" class="pull-right"></div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function () {
		send_notice_list(1);
	});
	
	function send_notice_list(currentIndex){
		 $("#course_notice_list").empty();
		 debugger;
		 $.ajax({
	            url: "course_notice_list?pageIndex=" + currentIndex + "&pageSize=" + 10,
	            type: "post",
	            success: function (result) {
	                var html = "";
	                //分页
	                new Page({
	                    parent: $("#copot-page"),
	                    nowPage: currentIndex,
	                    pageSize: 10,
	                    totalCount: result.total_count,
	                    setting: {
	                        defaultPage: 7,//默认显示可点击分页的个数
	                        firstPageText: "首页",
	                        prevPageText: "上一页",
	                        nextPageText: "下一页",
	                        lastPageText: "尾页"
	                    },
	                    callback: function (nowPage, totalPage) {
	                    	send_notice_list(nowPage);
	                    }
	                });
	                
	                var sendtime =null;
	                Date.prototype.pattern = function (fmt) {
	                    var o = {
	                        "M+": this.getMonth() + 1, //月份
	                        "d+": this.getDate(), //日
	                        "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时
	                        "H+": this.getHours(), //小时
	                        "m+": this.getMinutes(), //分
	                        "s+": this.getSeconds(), //秒
	                        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
	                        "S": this.getMilliseconds() //毫秒
	                    };
	                    var week = {
	                        "0": "/u65e5",
	                        "1": "/u4e00",
	                        "2": "/u4e8c",
	                        "3": "/u4e09",
	                        "4": "/u56db",
	                        "5": "/u4e94",
	                        "6": "/u516d"
	                    };
	                    if (/(y+)/.test(fmt)) {
	                        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	                    }
	                    if (/(E+)/.test(fmt)) {
	                        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "/u661f/u671f" : "/u5468") : "") + week[this.getDay() + ""]);
	                    }
	                    for (var k in o) {
	                        if (new RegExp("(" + k + ")").test(fmt)) {
	                            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	                        }
	                    }
	                    var str = fmt.lastIndexOf("N");
	                    if (str != -1) {
	                        return "";
	                    }

	                    return fmt;
	                }
	                
	                $("#total_count").text(result.total_count);
	                $.each(result.course_notice_list, function (i, result) {
	                	
	                	 if (result.sendtime) {
	                		 sendtime = new Date(result.sendtime).pattern("yyyy-MM-dd HH:mm");
	                     } else {
	                    	 sendtime = "无数据";
	                     }
	                	 
	                    html += "<tr><td>" + result.id + "</td>";
	                    html += "<td>" + result.title + "</td>";
	                    html += "<td>" + result.storeids + "</td>";
	                    html += "<td>" + result.sendTypeName + "</td>";
	                    html += "<td>" + result.createPersonName + "</td>";
	                    html += "<td>" + sendtime + "</td>";
	                    html += "<td>";
	                    if(result.sendTypeName == '未开始'){
	                    	html += "<button type='button' onclick='editCourseNotice(" + result.id + ")' class='btn btn-default'><i class='fa fa-pencil'></i> 编辑</button>";	
	                    	html += "<button type='button' onclick='delCourseNotice(" + result.id + ")' class='btn btn-default'><i class='fa fa-pencil'></i> 结束</button>";
	                    }
	                    html+="</td>"
	                    html += "</tr>";
	                });
	                $("#course_notice_list").html(html);
	            }
	        });
	}
	
	function editCourseNotice(id){
		window.location = "to_course_notice_edit?id=" + id;
	}
	function delCourseNotice(id){
		swal({
            title: "确定要结束吗?",
            text: "点击删除后该课程通知将立即变为结束状态!",
            type: "warning",
            showCancelButton: true,
            cancelButtonText: "容我三思！",
            confirmButtonText: "结束!"
        }).then(function () {
            $.ajax({
                type: "post",
                url: "course_notice_close",
                data: {"id": id},
                success: function (result) {
                    if (result) {
                        swal("下架成功!", "页面即将重新加载,请稍后...", "success");
                        window.setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    }
                }
            });
        });
	}

</script>

</@body.page>
</html>